/*
    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/

#pragma once

//read as
//input1 rangeRelation input2
enum RangeRelation
{
	Inside,
	Outside,
	Overlaps,
	Surrounds
};

enum VoxelType
{
	Nil,
	Solid,
	Both
};

template<class T>
inline
RangeRelation checkRange(const T& a,
		const T& b1, const T& b2)
{

	if((a<b1) && (a<b2))
		return Outside;
	if((a>b1) && (a>b2))
		return Outside;
	return Inside;
}

template<class T>
inline RangeRelation checkRangesSorted(const T& ami, const T& ama,
		const T& bmi, const T& bma)
{
	if((ama<bmi) || (ami>bma))
		return Outside;
	if((ami>=bmi) && (ama<=bma))
		return Inside;
	if((bmi>=ami) && (bma<=ama))
		return Surrounds;
	return Overlaps;
}

template<class T>
RangeRelation checkRanges(const T& a1, const T& a2,
		const T& b1, const T& b2)
{
	//sort
	T bmi, bma;
	if(b2>b1)
	{
		bmi=b1;
		bma=b2;
	}
	else
	{
		bmi=b2;
		bma=b1;
	}
	T ami, ama;
	if(a2>a1)
	{
		ami=a1;
		ama=a2;
	}
	else
	{
		ami=a2;
		ama=a1;
	}

	return checkRangesSorted(ami, ama, bmi, bma);
}

inline VoxelType
relationToVoxel(const RangeRelation& rel)
{
	switch(rel)
	{
	case Outside:
		return Nil;
	case Inside:
		return Solid;
	default:
		return Both;
	}
}
